package com.sky.controller;

import com.sky.dto.ClassPageQueryDTO;
import com.sky.entity.Clazz;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ClazzService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import static com.baomidou.mybatisplus.core.toolkit.IdWorker.getId;

/**
 * @author LiZhiHan
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("class")
public class ClassController {

	private final ClazzService clazzService;


	/**
	 * 新增
	 *
	 * @param clazz
	 * @return 返回主键id
	 */
	@PostMapping("/save")
	public Result<Integer> save(@RequestBody Clazz clazz) {
		clazzService.save(clazz);
		// 返回添加后的主键值
		return Result.success(clazz.getId());
	}

	@GetMapping("/classList")
	public Result<PageResult> classPage(ClassPageQueryDTO classPageQueryDTO) {
		log.info("classPageQueryDTO");
		return Result.success(clazzService.pageQuery(classPageQueryDTO));
	}

}
